/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import util.IncompleteFile;

/**
 *
 * @author Victor
 */
public class DownloadItem extends javax.swing.JPanel {

    
    private boolean isVisible;  // Indicates if download item is visible on main list
    private int progress;       //Inteiro (0 - 100) que indica a porcentagem do progresso do download
    private String fileName;        //Nome do arquivo
    private int id;             //Id para buscas
    private IncompleteFile file;
    
    /**
     * Creates new form DownloadItem
     */
    public DownloadItem(int id, IncompleteFile file) {
        this.fileName = file.getName();
        initComponents();
        setId(id);

        this.downloadSpeedField.setText("0 kB/s");
        this.nameField.setText(fileName);
        
        //VALOR INICIAL. VERIFICAR STATUS DO ARQUIVO
        this.progressBar.setValue(50);
    }

        /**
     * @param progress the progress to set
     */
    public int getProgress() {
        return this.progress;
    }
    
    /**
     * @param progress the progress to set
     */
    public void setProgress(int progress) {
        this.progress = progress;
    }

    /**
     * @return the name
     */
    public String getName() {
        return fileName;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.fileName = name;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nameField = new javax.swing.JTextField();
        downloadSpeedField = new javax.swing.JTextField();
        progressBar = new javax.swing.JProgressBar();

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));

        nameField.setEditable(false);
        nameField.setBackground(new java.awt.Color(255, 255, 255));
        nameField.setFont(new java.awt.Font("Dotum", 0, 12)); // NOI18N
        nameField.setForeground(new java.awt.Color(51, 51, 51));
        nameField.setText("jTextField1");
        nameField.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        nameField.setMargin(new java.awt.Insets(0, 0, 0, 0));
        nameField.setMinimumSize(new java.awt.Dimension(10, 10));
        nameField.setPreferredSize(new java.awt.Dimension(60, 25));

        downloadSpeedField.setEditable(false);
        downloadSpeedField.setBackground(new java.awt.Color(255, 255, 255));
        downloadSpeedField.setFont(new java.awt.Font("Dotum", 0, 12)); // NOI18N
        downloadSpeedField.setForeground(new java.awt.Color(51, 51, 51));
        downloadSpeedField.setText("4000kb/s");
        downloadSpeedField.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        downloadSpeedField.setMargin(new java.awt.Insets(0, 0, 0, 0));
        downloadSpeedField.setMinimumSize(new java.awt.Dimension(10, 10));

        progressBar.setBorderPainted(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(nameField, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(downloadSpeedField, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(downloadSpeedField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 0, 0))
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField downloadSpeedField;
    private javax.swing.JTextField nameField;
    private javax.swing.JProgressBar progressBar;
    // End of variables declaration//GEN-END:variables

    void refresh() {
        progressBar.setValue(this.progress);
        repaint();
    }
}
